<?php //由ThinkphpHelper自动生成,请根据需要修改
namespace Test\Controller;

class DocumentController extends  {

	public function add(){
	if(IS_POST){
		$documentModel = M('Document');
		$documentModel ->create();
		$flag = $documentModel ->add();
		if($flag){
			$this->success('新建成功',U('Document/all')); 
		}else{
			$this->error('新建失败',U('Document/all')); 
		}
	}else{
		$this->display(); 
	}
}

public function delete(){
	$documentModel = M('document');
	$id = I('id'); 
	$flag = $documentModel->where('id='.$id)->delete();
	if($flag){
		$this->success('删除成功', U('Document/all'));
	}else{
		$this->error('删除失败', U('Document/all'));
	}
}

public function edit(){
	$documentModel = M('Document');
	if(IS_POST){
		$documentModel ->create();
		$flag = $documentModel ->save();
		if($flag){
			$this->success('编辑成功',U('Document/all')); 
		}else{
			$this->error('编辑失败',U('Document/all')); 
		}
	}else{
		$id = I('id'); 
		$document = $documentModel->find($id);
		$this->assign('document', $document);
		$this->display();
	}
}

public function index()
{
    $map = $this->_search();
    $documentList = $this->lists($this->model, $map);
    $this->assign('documentList', $documentList);
    $this->display();
}


}